<template>
  <div style="text-align: left">患者信息:
    <span style="font-size: 16px;background-color: beige;color: #42b983">
      姓名:{{info.realName}}
      病历号:{{info.caseNumber}}
      年龄:{{info.age}}
      性别:{{info.sex}}

  </span>
  </div>
  <hr/>
  检查结果
  <hr/>
  <el-table :data="checkItemList" style="width: 100%"
            highlight-current-row
            @current-change="showRow">

    <el-table-column prop="id" label="编号"/>
    <el-table-column prop="techName" label="检查名称"/>
    <el-table-column prop="techFormat" label="检查规格"/>
    <el-table-column prop="techPrice" label="单价"/>
    <el-table-column prop="checkState" label="状态"/>
    <el-table-column prop="priceType" label="费用类型"/>
  </el-table>
  <hr/>
  <div style="text-align: left;font-weight: bolder">
    检查结果详情:
  </div>
  <el-form :model="formChecked" label-width="auto" style="max-width: 100%">
    <el-form-item label="开立时间">
      <el-input v-model="formChecked.creationTime" readonly/>
    </el-form-item>
    <el-form-item label="检查医生">
      <el-input v-model="formChecked.checkEmp" readonly/>
    </el-form-item>
    <el-form-item label="检查部位">
      <el-input v-model="formChecked.checkPosition" readonly/>
    </el-form-item>
    <el-form-item label="目的要求">
      <el-input v-model="formChecked.checkInfo" readonly/>
    </el-form-item>
    <el-form-item label="医嘱备注">
      <el-input v-model="formChecked.checkRemark" readonly/>
    </el-form-item>
    <el-form-item label="检查结果">
      <el-input v-model="formChecked.checkResult" type="textarea" readonly/>
    </el-form-item>
    <el-form-item label="检查时间">
      <el-input v-model="formChecked.checkTime" readonly/>
    </el-form-item>

  </el-form>
</template>

<script setup>

import {onMounted, reactive, ref} from "vue";
import axios from "axios";
//患者个人信息
const info=reactive({
  realName:'',
  caseNumber:'',
  age:'',
  sex:''
});
//获取患者id
let item = sessionStorage.getItem("idKey");
/*let jsonItem=JSON.parse(item);
let id=jsonItem.id;*/
let id=0;
if(item){
  let jsonItem=JSON.parse(item);
  id=jsonItem.id;
}
console.log("id="+id)
//定义患者检查项列表
const checkItemList=ref([]);
//定义检查结果表单
const formChecked=reactive({
  creationTime:'',
  checkEmp:'',
  checkPosition:'',
  checkInfo:'',
  checkRemark:'',
  checkResult:'',
  checkTime:''
});
onMounted(()=>{
  getRegisterInfo();
  loadCheckedList();
})
/*定义函数加载病人信息*/
function getRegisterInfo(){

  axios.get("http://localhost/his/queryRegiserInfo/"+id)
      .then((response)=>{
        info.realName=response.data.realName;
        info.caseNumber=response.data.caseNumber;
        info.age=response.data.age;
        info.sex=response.data.gender	;
        //删除sessionStorage对象中保存的键值对

      })
      .catch((error)=>{
        console.log(error);
      });
}

/*发送ajax请求，加载某个病人已完成检查项列表*/
function loadCheckedList(){
  axios.get("http://localhost/his/queryCheckedList/"+id)
      .then((response)=>{
        checkItemList.value=response.data;
        //删除sessionStorage对象中保存的键值对

      })
      .catch((error)=>{
        console.log(error);
      });
}
/*选中某行需要触发的回调函数*/
function showRow(row){
  //var checkId=row.checkId;
  //console.log(checkId);
  axios.get("http://localhost/his/queryCheckResult/"+row.checkId)
      .then((response)=>{
        formChecked.creationTime=response.data.creationTime;
        formChecked.checkEmp=response.data.realname;
        formChecked.checkInfo=response.data.checkInfo;
        formChecked.checkPosition=response.data.checkPosition;
        formChecked.checkResult=response.data.checkResult;
        formChecked.checkRemark=response.data.checkRemark;
        formChecked.checkTime=response.data.checkTime;
      })
      .catch((error)=>{
        console.log(error);
      });
}

</script>

<style scoped>

</style>